/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("Plan_Summary_Three_Location",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using ATkg.BizAppProject.DomainModels;
using ATkg.BizAppProject.IServices;
using Microsoft.AspNetCore.Authorization;

namespace ATkg.BizAppProject.Controllers
{
    [Route("api/[controller]/[action]")]

    public partial class Plan_Summary_Three_LocationController
    {
        private readonly IPlan_Summary_Three_LocationService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public Plan_Summary_Three_LocationController(
            IPlan_Summary_Three_LocationService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }
        [HttpGet("GetInfoFromDbMes")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<JsonResult> GetInfoFromDbMes()
        {
            try
            {
                var r = await Service.DealDataFromLocation();
                return new JsonResult(new
                {
                    Success = true,
                    Message = "数据处理成功",
                    Data = r  // 新增：返回string格式的时间
                });

            }
            catch (Exception ex)
            {
                // 返回错误的 JsonResult
                return new JsonResult(new { Success = false, Message = $"处理失败: {ex.Message}" })
                {
                    StatusCode = 500 // 设置 HTTP 状态码
                };
            }


        }
        [HttpGet("GetDateFromDb")]
        public async Task<JsonResult> GetDateFromDb()
        {
            try
            {
                var r = await Service.GetDateFromDb();
                return new JsonResult(new
                {
                    Success = true,
                    Message = "数据处理成功",
                    Data = r  // 新增：返回string格式的时间
                });

            }
            catch (Exception ex)
            {
                // 返回错误的 JsonResult
                return new JsonResult(new { Success = false, Message = $"处理失败: {ex.Message}" })
                {
                    StatusCode = 500 // 设置 HTTP 状态码
                };
            }


        }
    }
}
